<template>
  <el-row>
    <el-table :data="rows" border stripe>
      <el-table-column label="首列" width="180">
        <template slot-scope="scope">
          {{scope.row.text}}
        </template>
      </el-table-column>
      <el-table-column :label="col" width="180" v-for="(col,i) in cols" :key="i">
        <template slot-scope="scope">
          {{answer(scope.row,col)}}
        </template>
      </el-table-column>
    </el-table>
  </el-row>
  <!--<el-row>-->
  <!--<div>行->[{{rows.join(',')}}]</div>-->
  <!--<div>列->[{{cols.join(',')}}]</div>-->
  <!--<div>选项->[{{options.join(',')}}]</div>-->
  <!--</el-row>-->
</template>

<script>
  export default {
    name: "view-i-table",
    props:['question'],
    data(){
      return{
        tableData:['a']
      }
    },
    created() {
      // console.log(this.question)
      //制作答案
    },
    computed:{
      // answer(e){
      //   console.log(e)
      // },
      rows(){
        let tmp = []
        let tmp2 = []
        let tmp3 = []
        if(this.question.answer){
          this.question.answer.forEach(r3=>tmp3.push(r3))
        }
        this.question.rows.forEach(r=>{
          tmp.push({text:r.text,answers:tmp3})
        })
        return tmp
      },
      cols(){
        let tmp = []
        this.question.cols.forEach(r=>tmp.push(r.text))
        // console.log(tmp)
        return tmp
      },
      options(){
        let tmp = []
        if(this.question.options)
          this.question.options.forEach(r=>tmp.push(r.text))
        // console.log(this.rows)
        return tmp
      }
    },
    methods: {
      test(scope){
        console.log(scope)
      },
      answer(row,i){
        // console.log(row,i)
        let tmp =[]
        let key = row.text+'_'+i
        row.answers.forEach(r=>{
          if(r.key === key){
            tmp = r.val
          }
        })
        let tmp2 = ''
        if(typeof  tmp === 'object' && tmp.length>=0){
          // console.log(tmp)
         tmp.forEach(t=>{
           tmp2 += t+','
         })
          tmp2 = tmp2.substring(0,tmp2.length-1)
        }else {
          tmp2 = tmp
        }
        return tmp2
      }
    }
  }
</script>

<style lang="scss">

</style>
